<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lzy">
    <title>lzy-</title>
    <style>
        
    </style>
</head>
<body>
    <img src="img/1.jpg" alt="">
    <button type="button" onclick="last()">上一页</button>
    <button type="button" onclick="next()">下一页</button>
</body>
</html>
<script>
    var img=document.querySelector('img');
    var current=1;
    function next(){
        current++;
        console.log(current);
        if(current>=5){
            alert('这是最后一张了');
            current=1;
           }
        img.src='img/'+current+'.jpg';
    }

    function last(){
        current--;
        if(current<=0){
            alert('这是第一张了');
            current=5;
        }
        img.src='img/'+current+'.jpg';
    }
</script>